﻿package plugin.instances.game
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.message.*;

    public class SuperTDCopyGame extends SuperTDCopyUI implements IInstance
    {
        private var curTB:int = 0;
        private var time:int = 0;
        private var _newMsg:Object;
        private var tween:TweenMax;
        private var _totalwave:int = 0;
        private var isshow:Boolean = true;

        public function SuperTDCopyGame()
        {
            guizeLabel.addEventListener(MouseEvent.ROLL_OVER, this.guizeOverHandler);
            guizeLabel.addEventListener(MouseEvent.ROLL_OUT, this.guizeOutHandler);
            return;
        }// end function

        protected function guizeOutHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function guizeOverHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "副本规则：" + "\n1、副本限时<font color = \'#53d436 \'>20分钟</font>" + "\n2、点击召唤<font color = \'#53d436 \'>守卫按钮</font>，在当前位置召唤出守卫来攻击怪物获得经验。" + "\n<font color = \'#53d436 \'>低级守卫</font>：消耗10w副本累积经验或低级守卫令牌（优先消耗道具）" + "\n<font color = \'#53d436 \'>高级守卫</font>：消耗5w金币或者高级守卫令牌（优先消耗道具）" + "\n3、可以在副本中的平台上走动，召唤守卫，合理放置守卫可获得更多的经验收益" + "\n4、塔防副本进入次数每天凌晨0点重置");
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_3:* = param2[InstancesPublic.INITSUPERTF];
            if (_loc_3 == null)
            {
                return;
            }
            this._newMsg = _loc_3;
            this._totalwave = _loc_3.wave + _loc_3.otherwaves;
            txt_dqbs.text = _loc_3.wave + "，共" + this._totalwave + "波";
            txt_gwsl.text = _loc_3.tb + "/15";
            txt_tbsl1.text = _loc_3.gainexp * 1000 + "";
            txt_tbzs1.text = _loc_3.loseexp * 1000 + "";
            expLabel.text = _loc_3.gainexp * 1000 + "/15000000";
            cd.width = 229 * (_loc_3.gainexp * 1000 / 15000000);
            ModelProxy.change("mainui", "gettdexp", _loc_3.gainexp);
            ModelProxy.change("data", "SuperTF", 15 - _loc_3.tb);
            ModelProxy.change("mainui", "updateTdStart", _loc_3.wave != 0);
            this.time = 0;
            txt_time.visible = false;
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:Point = null;
            for (_loc_3 in param2)
            {
                
                this._newMsg[_loc_3] = param2[_loc_3];
            }
            switch(param1)
            {
                case InstancesPublic.UPDATESTATUS:
                {
                    ModelProxy.change("mainui", "gettdexp", param2.gainexp * 1000);
                    if (int(txt_tbsl1.text) > int(param2.gainexp * 1000))
                    {
                        _loc_6 = cd.localToGlobal(new Point(cd.width, 0));
                        ModelProxy.change("mainui", "flytdEff", _loc_6);
                        TweenLite.to(cd, 0.8, {delay:0.8, width:229 * (param2.gainexp * 1000 / 15000000)});
                    }
                    else
                    {
                        TweenLite.to(cd, 0.8, {width:229 * (param2.gainexp * 1000 / 15000000)});
                    }
                    txt_tbsl1.text = param2.gainexp * 1000 + "";
                    txt_tbzs1.text = param2.loseexp * 1000 + "";
                    expLabel.text = param2.gainexp * 1000 + "/15000000";
                    if ((int(param2.gainexp) + int(param2.loseexp)) * 1000 == 15000000)
                    {
                        this.tween = TweenMax.to(btn_close, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    }
                    break;
                }
                case InstancesPublic.TIMECHECKER:
                {
                    _loc_4 = int(param2);
                    txt_time.text = TimeDataFormatUtil.getLeftTimeStr3(_loc_4);
                    txt_time.visible = true;
                    var _loc_7:String = this;
                    var _loc_8:* = this.time - 1;
                    _loc_7.time = _loc_8;
                    if (this.time == 10)
                    {
                        ModelProxy.change("mainui", "counter", {type:4, value:10});
                    }
                    break;
                }
                case InstancesPublic.NEXTWAVE:
                {
                    txt_dqbs.text = param2.wave + "，共" + this._totalwave + "波";
                    ModelProxy.change("mainui", "updateTdStart", param2.wave != 0);
                    break;
                }
                case InstancesPublic.INITSUPERTF:
                {
                    this._totalwave = param2.monumver;
                    ModelProxy.change("mainui", "updateTdStart", param2.wave != 0);
                    txt_dqbs.text = param2.wave + "，共" + this._totalwave + "波";
                    txt_gwsl.text = param2.tb + "/15";
                    txt_tbsl1.text = param2.gainexp * 1000 + "";
                    txt_tbzs1.text = param2.loseexp * 1000 + "";
                    expLabel.text = param2.gainexp * 1000 + "/15000000";
                    if ((int(param2.gainexp) + int(param2.loseexp)) * 1000 == 15000000)
                    {
                        this.tween = TweenMax.to(btn_close, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    }
                    cd.width = 229 * (param2.gainexp * 1000 / 15000000);
                    ModelProxy.change("data", "SuperTF", 15 - param2.tb);
                    txt_time.visible = true;
                    break;
                }
                case InstancesPublic.CREATESUPERTF:
                {
                    txt_gwsl.text = param2.tb + "/15";
                    _loc_5 = ModelProxy.getValue("data", "SuperTF");
                    if (_loc_5 == 0)
                    {
                        WarningManager.show(36, ["低级守卫", int(param2.tb)]);
                    }
                    else
                    {
                        WarningManager.show(36, ["高级守卫", int(param2.tb)]);
                    }
                    ModelProxy.change("data", "SuperTF", 15 - param2.tb);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            if (this.tween)
            {
                this.tween.kill();
                this.tween = null;
            }
            return;
        }// end function

        public function initEvent() : void
        {
            btn_close.clickHandler = new Handler(this.doClose);
            return;
        }// end function

        private function doClose() : void
        {
            if (this._newMsg.wave == this._totalwave)
            {
                ModelProxy.change("zone", "exitInstance", null);
            }
            else if (this.isshow)
            {
                Alert2.show("还未完成副本，退出将损失大量经验", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    ModelProxy.change("zone", "exitInstance", null);
                }
                else if (param1 == 100)
                {
                    isshow = false;
                    ModelProxy.change("zone", "exitInstance", null);
                }
                return;
            }// end function
            );
            }
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
